import pandas as pd
df = pd.read_csv('vgchartz-2024.csv', parse_dates=['release_date']).rename({
'title': 'Title',
'console': 'Console',
'genre': 'Genre',
'publisher': 'Publisher',
'developer': 'Developer'
}, axis=1).assign(release_year=lambda x:x['release_date'].dt.year)
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 64016 entries, 0 to 64015 Data columns (total 15 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 img 64016 non-null object 1 Title 64016 non-null object 2 Console 64016 non-null object 3 Genre 64016 non-null object 4 Publisher 64016 non-null object 5 Developer 63999 non-null object 6 critic_score 6678 non-null float64 7 total_sales 18922 non-null float64 8 na_sales 12637 non-null float64 9 jp_sales 6726 non-null float64 10 pal_sales 12824 non-null float64 11 other_sales 15128 non-null float64 12 release_date 56965 non-null datetime64[ns] 13 last_update 17879 non-null object 14 release_year 56965 non-null float64 dtypes: datetime64[ns](1), float64(7), object(7) memory usage: 7.3+ MB
df.describe()
| critic_score | total_sales | na_sales | jp_sales | pal_sales | other_sales | release_date | release_year | |
|---|---|---|---|---|---|---|---|---|
| count | 6678.000000 | 18922.000000 | 12637.000000 | 6726.000000 | 12824.000000 | 15128.000000 | 56965 | 56965.000000 |
| mean | 7.220440 | 0.349113 | 0.264740 | 0.102281 | 0.149472 | 0.043041 | 2006-11-14 06:33:03.491617792 | 2006.359572 |
| min | 1.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 1971-12-03 00:00:00 | 1971.000000 |
| 25% | 6.400000 | 0.030000 | 0.050000 | 0.020000 | 0.010000 | 0.000000 | 2001-03-28 00:00:00 | 2001.000000 |
| 50% | 7.500000 | 0.120000 | 0.120000 | 0.040000 | 0.040000 | 0.010000 | 2008-09-16 00:00:00 | 2008.000000 |
| 75% | 8.300000 | 0.340000 | 0.280000 | 0.120000 | 0.140000 | 0.030000 | 2012-12-27 00:00:00 | 2012.000000 |
| max | 10.000000 | 20.320000 | 9.760000 | 2.130000 | 9.850000 | 3.120000 | 2024-12-31 00:00:00 | 2024.000000 |
| std | 1.457066 | 0.807462 | 0.494787 | 0.168811 | 0.392653 | 0.126643 | NaN | 8.617813 |
df.head(15)
| img | Title | Console | Genre | Publisher | Developer | critic_score | total_sales | na_sales | jp_sales | pal_sales | other_sales | release_date | last_update | release_year | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | /games/boxart/full_6510540AmericaFrontccc.jpg | Grand Theft Auto V | PS3 | Action | Rockstar Games | Rockstar North | 9.4 | 20.32 | 6.37 | 0.99 | 9.85 | 3.12 | 2013-09-17 | NaN | 2013.0 |
| 1 | /games/boxart/full_5563178AmericaFrontccc.jpg | Grand Theft Auto V | PS4 | Action | Rockstar Games | Rockstar North | 9.7 | 19.39 | 6.06 | 0.60 | 9.71 | 3.02 | 2014-11-18 | 2018-01-03 | 2014.0 |
| 2 | /games/boxart/827563ccc.jpg | Grand Theft Auto: Vice City | PS2 | Action | Rockstar Games | Rockstar North | 9.6 | 16.15 | 8.41 | 0.47 | 5.49 | 1.78 | 2002-10-28 | NaN | 2002.0 |
| 3 | /games/boxart/full_9218923AmericaFrontccc.jpg | Grand Theft Auto V | X360 | Action | Rockstar Games | Rockstar North | NaN | 15.86 | 9.06 | 0.06 | 5.33 | 1.42 | 2013-09-17 | NaN | 2013.0 |
| 4 | /games/boxart/full_4990510AmericaFrontccc.jpg | Call of Duty: Black Ops 3 | PS4 | Shooter | Activision | Treyarch | 8.1 | 15.09 | 6.18 | 0.41 | 6.05 | 2.44 | 2015-11-06 | 2018-01-14 | 2015.0 |
| 5 | /games/boxart/full_call-of-duty-modern-warfare... | Call of Duty: Modern Warfare 3 | X360 | Shooter | Activision | Infinity Ward | 8.7 | 14.82 | 9.07 | 0.13 | 4.29 | 1.33 | 2011-11-08 | NaN | 2011.0 |
| 6 | /games/boxart/full_call-of-duty-black-ops_5Ame... | Call of Duty: Black Ops | X360 | Shooter | Activision | Treyarch | 8.8 | 14.74 | 9.76 | 0.11 | 3.73 | 1.14 | 2010-11-09 | NaN | 2010.0 |
| 7 | /games/boxart/full_4653215AmericaFrontccc.jpg | Red Dead Redemption 2 | PS4 | Action-Adventure | Rockstar Games | Rockstar Games | 9.8 | 13.94 | 5.26 | 0.21 | 6.21 | 2.26 | 2018-10-26 | 2018-11-02 | 2018.0 |
| 8 | /games/boxart/full_1977964AmericaFrontccc.jpg | Call of Duty: Black Ops II | X360 | Shooter | Activision | Treyarch | 8.4 | 13.86 | 8.27 | 0.07 | 4.32 | 1.20 | 2012-11-13 | 2018-04-07 | 2012.0 |
| 9 | /games/boxart/full_4649679AmericaFrontccc.png | Call of Duty: Black Ops II | PS3 | Shooter | Activision | Treyarch | 8.0 | 13.80 | 4.99 | 0.65 | 5.88 | 2.28 | 2012-11-13 | 2018-04-07 | 2012.0 |
| 10 | /games/boxart/full_809251AmericaFrontccc.jpg | Call of Duty: Modern Warfare 2 | X360 | Shooter | Activision | Infinity Ward | 9.5 | 13.53 | 8.54 | 0.08 | 3.63 | 1.28 | 2009-11-10 | NaN | 2009.0 |
| 11 | /games/boxart/full_4380292AmericaFrontccc.jpg | Call of Duty: WWII | PS4 | Shooter | Activision | Sledgehammer Games | 8.1 | 13.40 | 4.67 | 0.40 | 6.21 | 2.12 | 2017-11-03 | 2017-12-31 | 2017.0 |
| 12 | /games/boxart/full_call-of-duty-modern-warfare... | Call of Duty: Modern Warfare 3 | PS3 | Shooter | Activision | Infinity Ward | 8.8 | 13.35 | 5.54 | 0.49 | 5.78 | 1.54 | 2011-11-08 | NaN | 2011.0 |
| 13 | /games/boxart/3570928ccc.jpg | Grand Theft Auto III | PS2 | Action | Rockstar Games | DMA Design | 9.5 | 13.10 | 6.99 | 0.30 | 4.51 | 1.30 | 2001-10-23 | NaN | 2001.0 |
| 14 | /games/boxart/full_call-of-duty-black-ops_3Ame... | Call of Duty: Black Ops | PS3 | Shooter | Activision | Treyarch | 8.7 | 12.67 | 6.01 | 0.48 | 4.40 | 1.78 | 2010-11-09 | NaN | 2010.0 |
annual_sales=df.groupby('release_year').agg({'total_sales':'sum'}).reset_index()
annual_sales
| release_year | total_sales | |
|---|---|---|
| 0 | 1971.0 | 0.00 |
| 1 | 1973.0 | 0.00 |
| 2 | 1975.0 | 0.00 |
| 3 | 1977.0 | 2.50 |
| 4 | 1978.0 | 2.36 |
| 5 | 1979.0 | 0.31 |
| 6 | 1980.0 | 2.26 |
| 7 | 1981.0 | 7.73 |
| 8 | 1982.0 | 28.99 |
| 9 | 1983.0 | 22.68 |
| 10 | 1984.0 | 4.85 |
| 11 | 1985.0 | 2.19 |
| 12 | 1986.0 | 10.35 |
| 13 | 1987.0 | 5.59 |
| 14 | 1988.0 | 8.73 |
| 15 | 1989.0 | 9.12 |
| 16 | 1990.0 | 9.07 |
| 17 | 1991.0 | 6.05 |
| 18 | 1992.0 | 9.38 |
| 19 | 1993.0 | 20.16 |
| 20 | 1994.0 | 36.85 |
| 21 | 1995.0 | 52.98 |
| 22 | 1996.0 | 101.36 |
| 23 | 1997.0 | 105.89 |
| 24 | 1998.0 | 132.23 |
| 25 | 1999.0 | 169.61 |
| 26 | 2000.0 | 171.12 |
| 27 | 2001.0 | 226.75 |
| 28 | 2002.0 | 314.50 |
| 29 | 2003.0 | 300.89 |
| 30 | 2004.0 | 284.68 |
| 31 | 2005.0 | 313.48 |
| 32 | 2006.0 | 244.42 |
| 33 | 2007.0 | 436.39 |
| 34 | 2008.0 | 538.11 |
| 35 | 2009.0 | 495.36 |
| 36 | 2010.0 | 454.02 |
| 37 | 2011.0 | 440.32 |
| 38 | 2012.0 | 285.47 |
| 39 | 2013.0 | 266.00 |
| 40 | 2014.0 | 292.11 |
| 41 | 2015.0 | 230.45 |
| 42 | 2016.0 | 208.02 |
| 43 | 2017.0 | 191.96 |
| 44 | 2018.0 | 148.03 |
| 45 | 2019.0 | 2.55 |
| 46 | 2020.0 | 3.45 |
| 47 | 2021.0 | 0.00 |
| 48 | 2022.0 | 0.00 |
| 49 | 2023.0 | 0.00 |
| 50 | 2024.0 | 0.00 |
import plotly.express as px
fig = px.line(annual_sales, x='release_year', y='total_sales', title="Annual Sales Over Years")
fig.show()
top10_titles=(df.groupby('Title').agg({'total_sales':'sum'})
.reset_index()
.sort_values(by='total_sales',ascending=False)
.iloc[:10])
top10_titles
| Title | total_sales | |
|---|---|---|
| 13724 | Grand Theft Auto V | 64.29 |
| 5266 | Call of Duty: Black Ops | 30.99 |
| 5281 | Call of Duty: Modern Warfare 3 | 30.71 |
| 5273 | Call of Duty: Black Ops II | 29.59 |
| 5277 | Call of Duty: Ghosts | 28.80 |
| 5271 | Call of Duty: Black Ops 3 | 26.72 |
| 5280 | Call of Duty: Modern Warfare 2 | 25.02 |
| 20998 | Minecraft | 24.01 |
| 13719 | Grand Theft Auto IV | 22.53 |
| 5265 | Call of Duty: Advanced Warfare | 21.78 |
px.bar(top10_titles,x='Title',y='total_sales')
pip install dash
Collecting dash Obtaining dependency information for dash from https://files.pythonhosted.org/packages/3c/ea/227b2108053c7f38c175e884a45daf8cee112719499581be8cc137ecc19d/dash-2.18.1-py3-none-any.whl.metadata Downloading dash-2.18.1-py3-none-any.whl.metadata (10 kB) Requirement already satisfied: Flask<3.1,>=1.0.4 in c:\users\syuan\anaconda3\lib\site-packages (from dash) (2.2.2) Requirement already satisfied: Werkzeug<3.1 in c:\users\syuan\anaconda3\lib\site-packages (from dash) (2.2.3) Requirement already satisfied: plotly>=5.0.0 in c:\users\syuan\anaconda3\lib\site-packages (from dash) (5.9.0) Collecting dash-html-components==2.0.0 (from dash) Obtaining dependency information for dash-html-components==2.0.0 from https://files.pythonhosted.org/packages/75/65/1b16b853844ef59b2742a7de74a598f376ac0ab581f0dcc34db294e5c90e/dash_html_components-2.0.0-py3-none-any.whl.metadata Downloading dash_html_components-2.0.0-py3-none-any.whl.metadata (3.8 kB) Collecting dash-core-components==2.0.0 (from dash) Obtaining dependency information for dash-core-components==2.0.0 from https://files.pythonhosted.org/packages/00/9e/a29f726e84e531a36d56cff187e61d8c96d2cc253c5bcef9a7695acb7e6a/dash_core_components-2.0.0-py3-none-any.whl.metadata Downloading dash_core_components-2.0.0-py3-none-any.whl.metadata (2.9 kB) Collecting dash-table==5.0.0 (from dash) Obtaining dependency information for dash-table==5.0.0 from https://files.pythonhosted.org/packages/da/ce/43f77dc8e7bbad02a9f88d07bf794eaf68359df756a28bb9f2f78e255bb1/dash_table-5.0.0-py3-none-any.whl.metadata Downloading dash_table-5.0.0-py3-none-any.whl.metadata (2.4 kB) Requirement already satisfied: importlib-metadata in c:\users\syuan\anaconda3\lib\site-packages (from dash) (6.0.0) Requirement already satisfied: typing-extensions>=4.1.1 in c:\users\syuan\anaconda3\lib\site-packages (from dash) (4.10.0) Requirement already satisfied: requests in c:\users\syuan\anaconda3\lib\site-packages (from dash) (2.31.0) Collecting retrying (from dash) Obtaining dependency information for retrying from https://files.pythonhosted.org/packages/8f/04/9e36f28be4c0532c0e9207ff9dc01fb13a2b0eb036476a213b0000837d0e/retrying-1.3.4-py3-none-any.whl.metadata Downloading retrying-1.3.4-py3-none-any.whl.metadata (6.9 kB) Requirement already satisfied: nest-asyncio in c:\users\syuan\anaconda3\lib\site-packages (from dash) (1.5.6) Requirement already satisfied: setuptools in c:\users\syuan\anaconda3\lib\site-packages (from dash) (68.0.0) Requirement already satisfied: Jinja2>=3.0 in c:\users\syuan\anaconda3\lib\site-packages (from Flask<3.1,>=1.0.4->dash) (3.1.2) Requirement already satisfied: itsdangerous>=2.0 in c:\users\syuan\anaconda3\lib\site-packages (from Flask<3.1,>=1.0.4->dash) (2.0.1) Requirement already satisfied: click>=8.0 in c:\users\syuan\anaconda3\lib\site-packages (from Flask<3.1,>=1.0.4->dash) (8.0.4) Requirement already satisfied: tenacity>=6.2.0 in c:\users\syuan\anaconda3\lib\site-packages (from plotly>=5.0.0->dash) (8.2.2) Requirement already satisfied: MarkupSafe>=2.1.1 in c:\users\syuan\anaconda3\lib\site-packages (from Werkzeug<3.1->dash) (2.1.1) Requirement already satisfied: zipp>=0.5 in c:\users\syuan\anaconda3\lib\site-packages (from importlib-metadata->dash) (3.11.0) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash) (2.0.4) Requirement already satisfied: idna<4,>=2.5 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash) (3.4) Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash) (1.26.16) Requirement already satisfied: certifi>=2017.4.17 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash) (2024.2.2) Requirement already satisfied: six>=1.7.0 in c:\users\syuan\anaconda3\lib\site-packages (from retrying->dash) (1.16.0) Requirement already satisfied: colorama in c:\users\syuan\anaconda3\lib\site-packages (from click>=8.0->Flask<3.1,>=1.0.4->dash) (0.4.6) Downloading dash-2.18.1-py3-none-any.whl (7.5 MB) ---------------------------------------- 0.0/7.5 MB ? eta -:--:-- ---------------------------------------- 0.0/7.5 MB 991.0 kB/s eta 0:00:08 - -------------------------------------- 0.3/7.5 MB 3.8 MB/s eta 0:00:02 --- ------------------------------------ 0.7/7.5 MB 5.2 MB/s eta 0:00:02 ----- ---------------------------------- 1.0/7.5 MB 6.0 MB/s eta 0:00:02 ------- -------------------------------- 1.4/7.5 MB 6.4 MB/s eta 0:00:01 --------- ------------------------------ 1.8/7.5 MB 6.7 MB/s eta 0:00:01 ----------- ---------------------------- 2.1/7.5 MB 6.8 MB/s eta 0:00:01 ------------- -------------------------- 2.5/7.5 MB 7.0 MB/s eta 0:00:01 -------------- ------------------------- 2.7/7.5 MB 7.0 MB/s eta 0:00:01 ---------------- ----------------------- 3.1/7.5 MB 6.9 MB/s eta 0:00:01 ------------------ --------------------- 3.4/7.5 MB 6.9 MB/s eta 0:00:01 -------------------- ------------------- 3.9/7.5 MB 7.0 MB/s eta 0:00:01 -------------------- ------------------- 3.9/7.5 MB 6.9 MB/s eta 0:00:01 ----------------------- ---------------- 4.4/7.5 MB 6.9 MB/s eta 0:00:01 ------------------------- -------------- 4.8/7.5 MB 7.0 MB/s eta 0:00:01 --------------------------- ------------ 5.2/7.5 MB 7.1 MB/s eta 0:00:01 ----------------------------- ---------- 5.6/7.5 MB 7.1 MB/s eta 0:00:01 ------------------------------- -------- 5.9/7.5 MB 7.1 MB/s eta 0:00:01 --------------------------------- ------ 6.3/7.5 MB 7.2 MB/s eta 0:00:01 --------------------------------- ------ 6.3/7.5 MB 7.2 MB/s eta 0:00:01 ------------------------------------- -- 7.0/7.5 MB 7.2 MB/s eta 0:00:01 --------------------------------------- 7.4/7.5 MB 7.3 MB/s eta 0:00:01 ---------------------------------------- 7.5/7.5 MB 7.1 MB/s eta 0:00:00 Downloading dash_core_components-2.0.0-py3-none-any.whl (3.8 kB) Downloading dash_html_components-2.0.0-py3-none-any.whl (4.1 kB) Downloading dash_table-5.0.0-py3-none-any.whl (3.9 kB) Downloading retrying-1.3.4-py3-none-any.whl (11 kB) Installing collected packages: dash-table, dash-html-components, dash-core-components, retrying, dash Successfully installed dash-2.18.1 dash-core-components-2.0.0 dash-html-components-2.0.0 dash-table-5.0.0 retrying-1.3.4 Note: you may need to restart the kernel to use updated packages.
pip install dash-bootstrap-templates
Collecting dash-bootstrap-templates Obtaining dependency information for dash-bootstrap-templates from https://files.pythonhosted.org/packages/38/63/cbe79614edefaaf09dff3576a1fea7173b2d52620502d3b2607d36ae2609/dash_bootstrap_templates-1.2.4-py3-none-any.whl.metadata Downloading dash_bootstrap_templates-1.2.4-py3-none-any.whl.metadata (16 kB) Requirement already satisfied: dash in c:\users\syuan\anaconda3\lib\site-packages (from dash-bootstrap-templates) (2.18.1) Collecting dash-bootstrap-components>=1.0.0 (from dash-bootstrap-templates) Obtaining dependency information for dash-bootstrap-components>=1.0.0 from https://files.pythonhosted.org/packages/cc/72/dda12d6c6a9a2901f5549cea05c7f180e89dee6fb8c5f5f037ce7101ba24/dash_bootstrap_components-1.6.0-py3-none-any.whl.metadata Downloading dash_bootstrap_components-1.6.0-py3-none-any.whl.metadata (5.2 kB) Requirement already satisfied: numpy in c:\users\syuan\anaconda3\lib\site-packages (from dash-bootstrap-templates) (1.24.3) Requirement already satisfied: Flask<3.1,>=1.0.4 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (2.2.2) Requirement already satisfied: Werkzeug<3.1 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (2.2.3) Requirement already satisfied: plotly>=5.0.0 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (5.9.0) Requirement already satisfied: dash-html-components==2.0.0 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (2.0.0) Requirement already satisfied: dash-core-components==2.0.0 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (2.0.0) Requirement already satisfied: dash-table==5.0.0 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (5.0.0) Requirement already satisfied: importlib-metadata in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (6.0.0) Requirement already satisfied: typing-extensions>=4.1.1 in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (4.10.0) Requirement already satisfied: requests in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (2.31.0) Requirement already satisfied: retrying in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (1.3.4) Requirement already satisfied: nest-asyncio in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (1.5.6) Requirement already satisfied: setuptools in c:\users\syuan\anaconda3\lib\site-packages (from dash->dash-bootstrap-templates) (68.0.0) Requirement already satisfied: Jinja2>=3.0 in c:\users\syuan\anaconda3\lib\site-packages (from Flask<3.1,>=1.0.4->dash->dash-bootstrap-templates) (3.1.2) Requirement already satisfied: itsdangerous>=2.0 in c:\users\syuan\anaconda3\lib\site-packages (from Flask<3.1,>=1.0.4->dash->dash-bootstrap-templates) (2.0.1) Requirement already satisfied: click>=8.0 in c:\users\syuan\anaconda3\lib\site-packages (from Flask<3.1,>=1.0.4->dash->dash-bootstrap-templates) (8.0.4) Requirement already satisfied: tenacity>=6.2.0 in c:\users\syuan\anaconda3\lib\site-packages (from plotly>=5.0.0->dash->dash-bootstrap-templates) (8.2.2) Requirement already satisfied: MarkupSafe>=2.1.1 in c:\users\syuan\anaconda3\lib\site-packages (from Werkzeug<3.1->dash->dash-bootstrap-templates) (2.1.1) Requirement already satisfied: zipp>=0.5 in c:\users\syuan\anaconda3\lib\site-packages (from importlib-metadata->dash->dash-bootstrap-templates) (3.11.0) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash->dash-bootstrap-templates) (2.0.4) Requirement already satisfied: idna<4,>=2.5 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash->dash-bootstrap-templates) (3.4) Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash->dash-bootstrap-templates) (1.26.16) Requirement already satisfied: certifi>=2017.4.17 in c:\users\syuan\anaconda3\lib\site-packages (from requests->dash->dash-bootstrap-templates) (2024.2.2) Requirement already satisfied: six>=1.7.0 in c:\users\syuan\anaconda3\lib\site-packages (from retrying->dash->dash-bootstrap-templates) (1.16.0) Requirement already satisfied: colorama in c:\users\syuan\anaconda3\lib\site-packages (from click>=8.0->Flask<3.1,>=1.0.4->dash->dash-bootstrap-templates) (0.4.6) Downloading dash_bootstrap_templates-1.2.4-py3-none-any.whl (97 kB) ---------------------------------------- 0.0/97.2 kB ? eta -:--:-- ------------ --------------------------- 30.7/97.2 kB 640.0 kB/s eta 0:00:01 ---------------------------------------- 97.2/97.2 kB 1.1 MB/s eta 0:00:00 Downloading dash_bootstrap_components-1.6.0-py3-none-any.whl (222 kB) ---------------------------------------- 0.0/222.5 kB ? eta -:--:-- ---------------------------------------- 222.5/222.5 kB 6.8 MB/s eta 0:00:00 Installing collected packages: dash-bootstrap-components, dash-bootstrap-templates Successfully installed dash-bootstrap-components-1.6.0 dash-bootstrap-templates-1.2.4 Note: you may need to restart the kernel to use updated packages.
from dash import Dash, dcc, html
from dash.dependencies import Output,Input
from dash_bootstrap_templates import load_figure_template
import dash_bootstrap_components as dbc
import numpy as np
# Load and preprocess data
video_games = (
pd.read_csv('vgchartz-2024.csv', parse_dates=['release_date'])
.rename({
'title': 'Title',
'console': 'Console',
'genre': 'Genre',
'publisher': 'Publisher',
'developer': 'Developer'
}, axis=1)
.assign(release_year=lambda x: x['release_date'].dt.year)
)
dbc_css="https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates/dbc.min.css"
# Initialize Dash app
app = Dash(__name__,external_stylesheets=[dbc.themes.VAPOR,dbc_css])
load_figure_template("VAPOR")
# Define layout
app.layout = dbc.Container([
html.H1("Video Game Explorer", style={"text-align": "center"}),
# Category selection row
dbc.Row([
dbc.Col([
dbc.Card([
dcc.Markdown("**Select a Category**"),
dcc.Dropdown(
id='category-dropdown',
options=[
{"label": "Title", "value": "Title"},
{"label": "Genre", "value": "Genre"},
{"label": "Publisher", "value": "Publisher"},
{"label": "Developer", "value": "Developer"},
{"label": "Console", "value": "Console"},
],
value="Title",
className="dbc"
)
])
])
], className="mb-3"),
# Region selection row
dbc.Row([
dbc.Col([
dbc.Card([
dcc.Markdown("**Select a Region**"),
dcc.RadioItems(
id='region-radio',
options=[
{"label": "World Total", "value": "total_sales"},
{"label": "North America", "value": "na_sales"},
{"label": "Japan", "value": "jp_sales"},
{"label": "Europe/Africa", "value": "pal_sales"},
{"label": "Rest of World", "value": "other_sales"},
],
value="total_sales",
className="dbc"
)
])
])
], className="mb-3"),
html.Br(),
dbc.Row(dcc.Graph(id='sales_line')),
html.Br(),
dbc.Row(dcc.Graph(id='rankings_bar')),
])
@app.callback(
Output("sales_line","figure"),
Output("rankings_bar","figure"),
Input("category-dropdown","value"),
Input("region-radio","value"),
)
def vg_plotter(category,region):
annual_sales=video_games.groupby("release_year",as_index=False).agg({region:"sum"})
fig=px.line(
annual_sales,
x='release_year',
y=region, title=f"Video Game Sales in {region} Over Time").update_layout(title_x=0.5)
top10_sellers=(video_games.groupby(category,as_index=False).agg({region:'sum'})
.reset_index()
.sort_values(region,ascending=False)
.iloc[:10])
fig2=px.bar(
top10_sellers,
x=category,
y=region,
title=f"Top Video Game Sales by Category").update_layout(title_x=0.5)
return fig,fig2
# Run server
if __name__ == "__main__":
app.run_server(debug=True)